package me.zhengjie.modules.system.service.dto

import cn.hutool.core.bean.BeanUtil
import cn.hutool.core.bean.copier.CopyOptions
import com.fasterxml.jackson.annotation.JsonTypeInfo
import com.fasterxml.jackson.annotation.JsonTypeName
import me.zhengjie.common.annotation.Query
import me.zhengjie.common.utils.JacksonUtil
import org.apache.commons.lang3.builder.ToStringBuilder


/**
 * @author kuki
 * @date 2022-07-21
 */
@JsonTypeName("ProvinceQueryCriteria")
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS)
data class ProvinceQueryCriteria (
    // 模糊
    @Query(type = Query.Type.INNER_LIKE)
    private val name: String? = null,

    // 模糊
    @Query(type = Query.Type.INNER_LIKE)
    private val nameChs: String? = null,

    // 模糊
    @Query(type = Query.Type.INNER_LIKE)
    private val nameEn: String? = null,

    // 精确
    @Query
    private val provinceCode: Long? = null
){
    annotation class Update

    companion object {
        fun fromJson(json: String): ProvinceQueryCriteria? {
            val obj=JacksonUtil.parseObject(json, ProvinceQueryCriteria::class.java)!!
            return when(obj){
                is ProvinceQueryCriteria -> obj
                else -> null
            }
        }
    }
    fun tojson():String? {
        return JacksonUtil.toJSONString(this)
    }

    fun copy(source: ProvinceQueryCriteria?) {
        BeanUtil.copyProperties(source, this, CopyOptions.create().setIgnoreNullValue(true))
    }
}